<?php 
require_once 'ckLogin.php';
require_once 'init.php';
require_once 'dbClasses'.DIRECTORY_SEPARATOR.'config.php';
require_once 'dbClasses'.DIRECTORY_SEPARATOR.'dbConn.php';
$db = new dbConn();
//定义表名
define("TABLENAME","fanhuan_category");
//提交处理
if(strtoupper($_SERVER['REQUEST_METHOD'])=='POST'){
	if($_GET['act']=="update"){
		$id = $_POST['id'];
		$cate = $_POST['cate'];
		$cate_pic = $_POST['cate_pic'];
		$sort = $_POST['sort'];
		$db->sql="UPDATE `".TABLENAME."` SET cate='".$cate."',sort=".$sort.",cate_pic='".$cate_pic."' WHERE id=".$id;
		$db->doExecute();
	}
	if($_GET['act']=="insert"){
		$cate = $_POST['cate2'];
		$cate_pic = $_POST['cate_pic2'];
		$sort = $_POST['sort2'];
		$db->sql="INSERT INTO `".TABLENAME."`(cate,cate_pic,sort,create_time)  VALUES('".$cate."','".$cate_pic."',".$sort.",".time().")";
		$db->doExecute();
	}
}

if(!empty($_GET['act'])){
	$act = $_GET['act'];
	if($act == 'del'){
		$db->sql = "DELETE FROM `".TABLENAME."` WHERE id = ".$_GET['id'];
		$db->doExecute();
	}
}

$db->sql = "SELECT * FROM `".TABLENAME."` ORDER BY `sort`";
$category = $db->doResultList2();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo APPLICATION;?></title>
<!--                       CSS                       -->
<!-- Reset Stylesheet -->
<link rel="stylesheet" href="resources/css/reset.css" type="text/css" media="screen" />
<!-- Main Stylesheet -->
<link rel="stylesheet" href="resources/css/main.css" type="text/css" media="screen" />
<!-- Invalid Stylesheet. This makes stuff look pretty. Remove it if you want the CSS completely valid -->
<link rel="stylesheet" href="resources/css/invalid.css" type="text/css" media="screen" />

<!-- jQuery -->
<script type="text/javascript" src="resources/scripts/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
$(function($) {
	
	$(".deleteUser").click(function(){
		if(!confirm("确定删除这个分类?")){
			return false;
		}
	});
	$(".catids").click(function(){
		var cateid = $(this).parent("td").siblings().eq(0).text();
		var cate   = $(this).parent("td").siblings().eq(1).text();
		var sort   = $(this).parent("td").siblings().eq(2).text();
		$("#cate").val(cate);
		$("#sort").val(sort);
		$("#id").val(cateid);
		$("#message_click").click();
		
	});
	$("#add-new-cate-button").click(function(){
		$("#add-new-cate-tr").show();
		$("#add-new-cate-notice").show();
	});
	$("#add-new-cate-subm").click(function(){
		$('#add-new-cate-form').submit();
	});
});
</script>
<!-- jQuery Configuration -->
<script type="text/javascript"
	src="resources/scripts/simpla.jquery.configuration.js"></script>
<!-- Facebox jQuery Plugin -->
<script type="text/javascript" src="resources/scripts/facebox.js"></script>
<!-- jQuery WYSIWYG Plugin -->
<script type="text/javascript" src="resources/scripts/jquery.wysiwyg.js"></script>

</head>

<body>
	<div id="body-wrapper">
		<!-- Wrapper for the radial gradient background -->
		<a href="#messages" rel="modal" id="message_click"></a>
		<div id="messages" style="display: none;">
			<!-- Messages are shown when a link with these attributes are clicked: href="#messages" rel="modal"  -->
			<p>
				<strong>信息更新修改</strong>
			</p>
			<form action="?act=update" method="post">
				<fieldset>
					分类：
					<input class="text-input " type="text" id="cate" name="cate" style="width: 300px;"/><br />
					排序：
					<input class="text-input " type="text" id="sort" name="sort" style="width: 300px;"/><br />
					<input id="id" name="id" type="hidden" value="" />
					<input class="button" type="submit" value="修改" /> 
					<a href="javascript:void(0);" onclick="$(this).parents('#facebox').hide();">关闭</a>
				</fieldset>
			</form>
		</div>
		<!-- End #messages -->
		<div id="main-content">
			<!-- Page Head -->
			<h2>欢迎使用<span style="color:red;">返还网商品</span>管理后台</h2>
			<p id="page-intro">分类管理</p>

			<div class="clear"></div>
			<!-- End .clear -->

			<div class="content-box">
				<!-- Start Content Box -->

				<div class="content-box-header">

					<h3>商品分类 </h3>

					<div class="clear"></div>

				</div>
				<!-- End .content-box-header -->

				<div class="content-box-content">

				<!-- Start Notifications -->
				
				<div class="notification success png_bg" style="display: none;">
					<a href="#" class="close"><img
						src="resources/images/icons/cross_grey_small.png"
						title="Close this notification" alt="close" /></a>
					<div>
						修改成功
					</div>
				</div>
				
				<div class="notification error png_bg" style="display: none;">
					<a href="#" class="close"><img
						src="resources/images/icons/cross_grey_small.png"
						title="Close this notification" alt="close" /></a>
					<div>
					修改失败
					</div>
				</div>
				
				<!-- End Notifications -->
				
					<div class="tab-content default-tab" id="tab1">
						<!-- This is the target div. id must match the href of this div's tab -->

						<table>
							<thead>
								<tr>
									<th>编号</th>
									<th>分类</th>
									<th>排序</th>
									<th>操作</th>
								</tr>
							</thead>
							<tbody>
							<?php if(count($category)>0):?>
							<?php foreach ($category as $key=>$item):?>
								<tr>
									<td><?php echo $item['id'];?></td>
									<td><?php echo $item['cate'];?></td>
									<td><?php echo $item['sort'];?></td>
									<td>
										<a class="catids" href="javascript:void(0);">修改</a>
										<a class="deleteUser" href="?id=<?php echo $item['id'];?>&act=del">删除</a>
									</td>
								</tr>
							<?php endforeach;?>
							<?php else:?>
								<tr style="font-size: 50px;text-align: center; font-weight: bold;"><td colspan="5" style="text-align: center;">没有分类</td></tr>
							<?php endif;?>
								<tr id="add-new-cate-tr" style="display: none;">
								<form id="add-new-cate-form" action="?act=insert" method="post">
									<td></td>
									<td><input class="text-input " type="text" id="cate2" name="cate2" style="width: 100px;"/></td>
									<td><input class="text-input " type="text" id="sort2" name="sort2" style="width: 100px;"/></td>
									<td><a id="add-new-cate-subm" href="javascript:void(0);">提交</a></td>
								</form>
								</tr>
							</tbody>
						</table>
					</div>
					<!-- End #tab2 -->
					<!--  <span id="add-new-cate-notice" style="color: red;display: none;">图片填写示例：“content/cate/01.jpg”。 图片请上传到content/cate目录，若上传时提示文件已经存在，请重新命名再传！</span>
					 --><br class="clear" />
					<a href="javascript:void(0);" id="add-new-cate-button">添加分类</a>
				</div>
				<!-- End .content-box-content -->
			</div>
			<!-- End .content-box -->
			
			<div class="clear"></div>

			<div id="footer">
				<small> <!-- Remove this notice or replace it with whatever you want -->
					&#169; Copyright 2009 Your Company | Powered by <a
					href="http://themeforest.net/item/simpla-admin-flexible-user-friendly-admin-skin/46073">Simpla
						Admin</a> | <a href="#">Top</a>
				</small>
			</div>
			<!-- End #footer -->

		</div>
		<!-- End #main-content -->

	</div>
</body>


<!-- Download From www.exet.tk-->
</html>
